Engine.Transform = function(){
    this.position = new Engine.Vector3(0,0,0);
    this.rotation = new Engine.Vector3(0,0,0);
    this.scale = new Engine.Vector3(1,1,1);
  
    
};

Engine.Transform.prototype = (function(){
    var getRotationX = function (degree){
    	var radian = degree / 180 * Math.PI;
    	var matrix =  new Engine.Matrix4x4();

    	matrix.m00 = 1;
    	matrix.m11 = Math.cos(radian);
    	matrix.m12 = -Math.sin(radian);
    	matrix.m21 = Math.sin(radian);
    	matrix.m22 = Math.cos(radian);
    	matrix.m33 = 1;

    	return matrix;
    };

    var getRotationY = function (degree){
    	var radian = degree / 180 * Math.PI;
    	var matrix =  new Engine.Matrix4x4();

    	matrix.m00 = Math.cos(radian);
    	matrix.m02 = Math.sin(radian);
    	matrix.m11 = 1;
    	matrix.m20 = -Math.sin(radian);
    	matrix.m22 = Math.cos(radian);
    	matrix.m33 = 1;

    	return matrix;
    };


    var getRotationZ = function (degree){
    	var radian = degree / 180 * Math.PI;
    	var matrix =  new Engine.Matrix4x4();

    	matrix.m00 = Math.cos(radian);
    	matrix.m01 = -Math.sin(radian);
    	matrix.m10 = Math.sin(radian);
    	matrix.m11 = Math.cos(radian);
    	matrix.m22 = 1;
    	matrix.m33 = 1;

    	return matrix;
    };
    
    return {
        m2w:function(){
            var m = new Engine.Matrix4x4();
        	m.m00 = this.scale.x;
        	m.m11 = this.scale.y;
        	m.m22 = this.scale.z;

        	m.m03 = this.position.x;
        	m.m13 = this.position.y;
        	m.m23 = this.position.z;
        	m.m33 = 1;

        	if(this.rotation.y != 0)
        	{
        	    m = m.multiply(getRotationY(this.rotation.y));
        	}
        	if(this.rotation.x != 0)
        	{
        	    m = m.multiply(getRotationX(this.rotation.x));
        	}

        	if(this.rotation.z != 0)
        	{
        	    m = m.multiply(getRotationZ(this.rotation.z));
        	}
        	return m;
        }
    };
})();